package ynu.beggar.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ynu.beggar.server.entities.DO.*;
import ynu.beggar.server.service.UserService;
import ynu.beggar.server.utils.JsonData;

@RestController
@RequestMapping(path = "/api/v1", produces = "application/json;charset=UTF-8")
@CrossOrigin(origins = "*")
public class UserController {

    private UserService userService;

    @Autowired
    private void setUserService(UserService userService) {
        this.userService = userService;
    }

    @PostMapping(path = "/register", consumes = {"application/json"})
    public JsonData register(@RequestBody UserRegisterDO info) {
        return userService.register(info);
    }

    @PostMapping("/login")
    public JsonData login(@RequestBody UserLoginDO userLoginDO) {
        return userService.login(userLoginDO);
    }

    @PostMapping("/user/changeInfo")
    public JsonData changeInfo(@RequestBody UserChangeInfoDO userChangeInfoDO,
                               @RequestAttribute UserBasicInfoDO userBasicInfoDO) {
        return userService.changeInfo(userChangeInfoDO, userBasicInfoDO);
    }

    @GetMapping("/user/getInfo")
    public JsonData getInfo(@RequestAttribute UserBasicInfoDO userBasicInfoDO) {
        return userService.getInfo(userBasicInfoDO);
    }

    @PostMapping("/user/sendAdvice")
    public JsonData sendAdvice(@RequestBody SuggestionDO suggestionDO,
                               @RequestAttribute UserBasicInfoDO userBasicInfoDO) {
        return userService.createSuggestion(suggestionDO, userBasicInfoDO);
    }

}
